From 099b4e4d0c750328a4420ee7fd825f06edd6d641 Mon Sep 17 00:00:00 2001 From: Michal Babej Date: Thu, 11 Oct 2018 12:19:34 +0300 Subject: [PATCH] [PATCH] Fix linker flags for Apple Gbp-Pq: Name 0001-Fix-linker-flags-for-Apple.patch --- CMakeLists.txt | 25 ++++++++++++++++++------- cmake/LLVM.cmake | 14 +++++++++++++- config.h.in.cmake | 5 ++--- lib/CL/devices/common.c | 2 +- 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 00de900..5ce911d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -647,14 +647,20 @@ set(ENABLE_SPIRV ${SPIRV} CACHE INTERNAL "SPIR-V enabled" FORCE) ###################################################################################### +# fully device-side printf on devices which support it (only CPU backend ATM), disabled by default. +# this requires 128bit integer support because of the code in "errol" float-to-string conversion routine +# the output is not 100% compatible with glibc's printf (%f with large argument prints zeroes after +# last significant digit - 16-18th digit or so, unlike glibc which prints digits up to decimal point). if(CLANG_HAS_RTLIB_128) option(ENABLE_POCL_FLOAT_CONVERSION "Enable use of pocl's own float-to-decimal conversion code in OpenCL printf(). Defaults to OFF (uses snprintf from C library). Requires compiler-rt." OFF) else() - set(ENABLE_POCL_FLOAT_CONVERSION OFF CACHE INTERNAL "rtlib") + set(ENABLE_POCL_FLOAT_CONVERSION OFF CACHE INTERNAL "pocl's own float-to-decimal conversion code") endif() unset(RTLIB_FLAG) if(ENABLE_POCL_FLOAT_CONVERSION) + # force link with Clang; otherwise not needed on x86 but in this case we need rtlib + set(LINK_WITH_CLANG ON CACHE INTERNAL "Link using Clang") set(RTLIB_FLAG "-DENABLE_POCL_FLOAT_CONVERSION") endif() @@ -696,21 +702,25 @@ if(UNIX) # MacOS ld outputs useless warnings like # ld: warning: -macosx_version_min not specificed, assuming 10.7 # suppress them with -w. - set(DEFAULT_HOST_LD_FLAGS "-dylib -w -lm") + if(LINK_WITH_CLANG) + set(DEFAULT_HOST_LD_FLAGS "-dynamiclib -w -lm") + else() + set(DEFAULT_HOST_LD_FLAGS "-dylib -w -lm") + endif() elseif(ANDROID_COMPILER) set(DEFAULT_HOST_LD_FLAGS "-L/system/lib/ -shared -ldl -lc -lm /system/lib/crtbegin_so.o /system/lib/crtend_so.o") else() - if(ENABLE_POCL_FLOAT_CONVERSION) - set(DEFAULT_HOST_LD_FLAGS "-shared -lm --rtlib=compiler-rt") - else() - set(DEFAULT_HOST_LD_FLAGS "-shared -lm") - endif() + set(DEFAULT_HOST_LD_FLAGS "-shared -lm") endif() set(LIBMATH "-lm") elseif(WIN32) set(LIBMATH) endif() +if(LINK_WITH_CLANG AND (CLANG_HAS_RTLIB_128 OR CLANG_HAS_RTLIB)) + set(DEFAULT_HOST_LD_FLAGS "${DEFAULT_HOST_LD_FLAGS} --rtlib=compiler-rt") +endif() + ###################################################################################### if(UNIX) @@ -1474,6 +1484,7 @@ if (OCS_AVAILABLE) MESSAGE(STATUS "") MESSAGE(STATUS "CLANG_HAS_RTLIB: ${CLANG_HAS_RTLIB}") MESSAGE(STATUS "CLANG_HAS_RTLIB_128: ${CLANG_HAS_RTLIB_128}") + MESSAGE(STATUS "LINK_WITH_CLANG: ${LINK_WITH_CLANG}") MESSAGE(STATUS "CLANG_MARCH_FLAG: ${CLANG_MARCH_FLAG}") MESSAGE(STATUS "CLANG_TARGET_OPTION: ${CLANG_TARGET_OPTION}") MESSAGE(STATUS "LLVM_VERSION: ${LLVM_VERSION}") diff --git a/cmake/LLVM.cmake b/cmake/LLVM.cmake index de841b0..0b7b32c 100644 --- a/cmake/LLVM.cmake +++ b/cmake/LLVM.cmake @@ -296,6 +296,7 @@ if(NOT DEFINED LLVM_SPIRV) message(STATUS "Found llvm-spirv: ${LLVM_SPIRV}") endif() endif() + #################################################################### # try compile with any compiler (supplied as argument) @@ -452,7 +453,7 @@ endif() #################################################################### #################################################################### -if(NOT DEFINED CLANG_HAS_RTLIB) +if(NOT DEFINED LINK_WITH_CLANG) set(RT128 OFF) set(RT64 OFF) @@ -483,6 +484,17 @@ if(NOT DEFINED CLANG_HAS_RTLIB) set(CLANG_HAS_RTLIB ${RT64} CACHE INTERNAL "Clang's compiler-rt available with 64bit types") set(CLANG_HAS_RTLIB_128 ${RT128} CACHE INTERNAL "Clang's compiler-rt available with 128bit types") + if(LLVM_OLDER_THAN_5_0) + if(X86) + set(LINK_WITH_CLANG OFF CACHE INTERNAL "Link using Clang") + else() + set(LINK_WITH_CLANG ON CACHE INTERNAL "Link using Clang") + endif() + else() + # on LLVM 5.0+ we use the library API directly instead of forking + set(LINK_WITH_CLANG ON CACHE INTERNAL "Link using Clang") + endif() + endif() #################################################################### diff --git a/config.h.in.cmake b/config.h.in.cmake index 5b7b758..a4d5873 100644 --- a/config.h.in.cmake +++ b/config.h.in.cmake @@ -9,9 +9,6 @@ #define CLANG "@CLANG@" -#cmakedefine CLANG_HAS_RTLIB -#cmakedefine CLANG_HAS_RTLIB_128 - #define CLANG_RESOURCE_DIR "@CLANG_RESOURCE_DIR@" /* clang++ executable */ @@ -130,6 +127,8 @@ #define LINK_COMMAND "@LINK_COMMAND@" +#cmakedefine LINK_WITH_CLANG + /* Defined to greatest expected alignment for extended types, in bytes. */ #define MAX_EXTENDED_ALIGNMENT @MAX_EXTENDED_ALIGNMENT@ diff --git a/lib/CL/devices/common.c b/lib/CL/devices/common.c index 6dc18d0..56e060c 100644 --- a/lib/CL/devices/common.c +++ b/lib/CL/devices/common.c @@ -198,7 +198,7 @@ llvm_codegen (const char* tmpdir, cl_kernel kernel, cl_device_id device, char *const args1[] #ifndef POCL_ANDROID /* use Clang as linker, when compiler-rt is available and needed */ -#if defined(ENABLE_POCL_FLOAT_CONVERSION) || defined(CLANG_HAS_RTLIB) +#if defined(LINK_WITH_CLANG) = { CLANG, #else = { LINK_COMMAND, -- 2.30.2